<%@page import="com.service.impl.TopicServiceImpl"%>
<%@page import="com.entity.Topic"%>
<%@page import="java.util.List"%>
<%@page import="com.service.TopicService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
</head>
<body>
	<form action="login" method="post">
		用户名:<input type="text" name="uname"> 密码:<input type="password"
			name="upwd"> <input type="submit" value="登陆">
		<%
			
			if (request.getParameter("msg") != null && request.getParameter("msg").equals("error")) {
		%>
		<span style="color: red;">用户名密码错误</span>
		<%
			}else if (request.getParameter("msg") != null && request.getParameter("msg").equals("logout")) {
				%>
				<span style="color: red;">退出成功</span>
				<%
					}
				%>
	</form>
	<h2>新闻主题</h2>
	<a href="news_list">全部</a>
	<%
		TopicService topicService = new TopicServiceImpl();
		List<Topic> topics = topicService.selectTopics();
		for (Topic topic : topics) {
	%>
	<a class="topic_menu" href="${pageContext.request.contextPath }/newListByTopic?tid=<%=topic.getTid()%>" tid="<%=topic.getTid()%>"><%=topic.getTname()%></a>
	<%
		}
	%>
	
	<div class="new_list" style="margin-top: 20px">
		
	</div>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
	<script type="text/javascript">
		$(".topic_menu").click(function(){
			$(".new_list").html("");
			var tid = $(this).attr("tid");
			var href = $(this).attr("href");
			$.ajax({
				url:href,
				type:"get",
				dataType:"json",
				success:function(data){
					for(var i in data){
						$(".new_list").append('<p><a href="news_detail.jsp?nid='+data[i].nid+'">'+data[i].ntitle+'</a></p>');
					}
				},
				error:function(data){
					$(".new_list").text("加载数据失败");
				}
				
				
			})
			
			return false;
		})
		
		
	</script>
</body>
</html>